<template>
  <li class="list-group-item">
    <div class="handle">
      <a href="javascript:;" @click="deleteItem">删除</a>
    </div>
    <p class="user"><span >{{ comment.name }}</span><span>说:</span></p>
    <p class="centence">{{comment.comment}}</p>
  </li>
</template>

<script>
  export default {
    name: 'Item',
    props: {// 接受父类组件传递过来的值，并且指定对应的类型为Object类型
      comment: Object,
      deleteComment: Function,
      index: Number // 定义为Number类型，接受从List组件传递来的组件
    },
    methods: {
      deleteItem () {
        const {comment, deleteComment, index} = this
        if(window.confirm(`确定要删除的${this.comment.name}评论？`)){// 使用${}解析组件中变量
          this.deleteComment(this.index)
        }
      }
    }
  }
</script>

<style scoped>

  li {
    transition: .5s;
    overflow: hidden;
  }

  .handle {
    width: 40px;
    border: 1px solid #ccc;
    background: #fff;
    position: absolute;
    right: 10px;
    top: 1px;
    text-align: center;
  }

  .handle a {
    display: block;
    text-decoration: none;
  }

  .list-group-item .centence {
    padding: 0px 50px;
  }

  .user {
    font-size: 22px;
  }

</style>
